import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Main',
        component: () =>
            import ('../views/Main.vue'),
        redirect: '/home',
        children: [
            /* {
                            path: '/home',
                            name: 'home',
                            component: () =>
                                import ('../views/home')
                        },
                        {
                            path: '/user',
                            name: 'user',
                            component: () =>
                                import ('../views/User')
                        },
                        {
                            path: '/mall',
                            name: 'mall',
                            component: () =>
                                import ('../views/mall')
                        }, */
            {
                path: '/page1',
                name: 'page1',
                component: () =>
                    import ('../views/Other/PageOne')
            },
            {
                path: '/page2',
                name: 'page2',
                component: () =>
                    import ('../views/Other/PageTwo')
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ('../views/Login/login.vue')
    }
]

const router = new VueRouter({
    mode: 'history',
    routes
})

// 解决：Uncaught (in promise) NavigationDuplicated; 重复点击路由报错
let originalPush = VueRouter.prototype.push; // 先保存一份 VueRouter.prototype.push方法
let originalRepace = VueRouter.prototype.replace;

VueRouter.prototype.push = function push(location) {
    // call(); 篡改上下文    catch(); 捕获异常 **** 
    return originalPush.call(this, location).catch(e => e);
}
VueRouter.prototype.replace = function replace(location) {
    return originalRepace.call(this, location).catch(e => e);
}
export default router